* ==============================================================================
* 		Date: September 2023
* 		Paper: Exposure to worrisome topics can increase cognitive performance
*		Version: Preliminary version at submission state
*
* This program cleans and prepares the data.  
* 
* database used: base_anonym_AMU.xlsx
* output: .dta
*
* ==============================================================================

clear

** !!!!!!!!!!!!!! add your working directory here ******************************
***** Working directory strucure:
****** Folders "Data"; "Codes"; "Output"
****** Data folder contains the raw dataset "base_anonym_AMU.xlsx"
****** Output folder contains following subfolders: "main figures"; "main tables"; "SI figures"; "SI tables"

import excel "Data/base_anonym_AMU.xlsx", sheet("Feuil1") firstrow

* Deleting missing values and no consent 
drop if idIDdelaréponse==. | ConsentJailuetjaicompris== "N" 


******** Rename variables: 
rename interviewtimeTempstotal timetotal
rename lastpageDernièrepage lastpage
rename B2Quelleestvotreannéedena birth
rename B5Quelestléchelondevotre level_bourse
rename B6otherEnquelleannéedétu schooling_oth
rename B9otherQuelestvotredomain field_oth
rename B10otherQuelleestvotrefac faculty_oth
rename GroupeAleaifis_emptyGroupeA treatment
rename ProbThresifis_emptyProbThre payment
rename groupTime422Duréepourlegrou timeecon
rename groupTime433Duréepourlegrou timesocial
rename groupTime434Duréepourlegrou timecontrol1
rename groupTime446Duréepourlegrou timecontrol2
rename GainsumifProba0RAval gainrisk
rename EmotAleaifis_emptyEmotAlea random_emotions
rename OuverteSivousvoulezfaireun comments
rename idIDdelaréponse id 
* Cognitive reasoning
rename CR1Alaboulangerievousache cr1
rename CR2Imaginezquevousinventiez cr2
rename CR3Imaginezquevoussoyezun cr3
rename groupTime430Duréepourlegrou timecr
* Cognitive reasoning awareness
rename CR4Cettequestionestsansrém crawar
* WTP
rename WTP0Voulezvousacheteruntic wtp0
rename WTP1Voulezvousacheteruntic wtp1
rename WTP2Voulezvousacheteruntic wtp2
rename WTP3Voulezvousacheteruntic wtp3




*-------------------------------------------------------------------------------
******** Generate treatment variables			

* Completed survey

* Day of survey
split ident, p("_") 
gen wave= real(substr(ident2,2,.))
gen sc_wave6= ident3=="2C" // To identify second chance in wave 6
gen date=date(submitdateDatedesoumission,"YMD###")
replace date= date(submitdateDatedesoumission,"MDY") if wave== 4 // Wave 4 has different format "3/4/2021"
replace date= date(submitdateDatedesoumission,"MDY##") if date==. & wave== 2  // Two obs have format "3/4/2021 1:58"
format date %td	
drop ident1 ident3 ident4

gen finish = (date!=.)
			
* Payment scheme
label define payment 0 "Threshold" 1 "Piece rate"
label value payment payment

* Treatment
label define treatment 1 "Labor Market" 2 "Mental Health" 3 "Animal welfare" 4 "Space"
label values treatment treatment

* Pooling controls 
gen treat1= treatment
recode treat1 (4=3)
label define treat1 1 "Labor Market" 2 "Mental Health" 3 "Both Controls"
label values treat1 treat1

 * Grouping controls
gen labor_market= treat1==1
gen mental_health= treat1==2

	* Labor market vs Both controls
gen econ_control=1 if treat1==1	
replace econ_control=0 if treat1==3

	* Mental Health vs Both controls
gen social_control=1 if treat1==2	
replace social_control=0 if treat1==3

* Emotions
recode random_emotions (1=0) (2=1)		
label define emotions 0 "Before" 1 "After"
label values random_emotions emotions	

gen treatment_after = treat1 if random_emotion == 1
replace treatment_after = 0 if random_emotion == 0
label define treatment_after 0 "Before Article" 1 "Labor Market" 2 "Mental Health" 3 "Both Controls"
label values treatment_after treatment_after

*-------------------------------------------------------------------------------
******** Generate main outcome variables

*** Congnitive Ability task: The correct matrix ALWAYS is 01 
* Training Matrix 
gen mtr= real(substr(Mtraining,3,4))
	* gen 1 if they answer correctly; 0 otherwise
gen Trm= mtr==1	 

* First round matrices
gen fr_m1= real(substr(M1tf1u30,3,4))
gen fr_m2= real(substr(M1tf1u64,3,4))
gen fr_m3= real(substr(M1tf2u14,3,4))
gen fr_m4= real(substr(M1tf2u52,3,4))

	* gen 1 if they answer correctly; 0 otherwise
foreach var of varlist fr_m* { 
	replace `var'=0 if `var'!=1 & `var'!=.  
 }  
egen Frm= rsum(fr_m1-fr_m4)


* Second round matrices
gen sr_m1= real(substr(M2tf2u29,3,4))
gen sr_m2= real(substr(M2tf1u67,3,4))
gen sr_m3= real(substr(M2tf2u24,3,4))
gen sr_m4= real(substr(M2tf1u35,3,4))
gen sr_m5= real(substr(M2tf2u46,3,4))
gen sr_m6= real(substr(M2tf2u21,3,4))
gen sr_m7= real(substr(M2tf2u42,3,4))
gen sr_m8= real(substr(M2tf3u17,3,4))
gen sr_m9= real(substr(M2tf3u61,3,4))
gen sr_m10= real(substr(M2tf3u36,3,4))

  	* gen 1 if they answer correctly; 0 otherwise
 foreach var of varlist sr_m* { 
	qui: replace `var'=0 if `var'!=1 & `var'!=.	
 } 

egen Srm= rsum(sr_m1-sr_m10)	
replace Srm=. if MontantM2ProbThressumif==.  // Replace as missing if participants didn't advance to the next task

	
*** Measures of confidence 
gen confidence_believed= real(substr(RM3Combiendebonnesréponses,3,4))
recode confidence_believed (1=0) (2=1) (3=2) (4=3) (5=4) (6=5) (7=6) (8=7) (9=8) (10=9) (11=10) 

* Confidence -- c= belief-truth
gen confidence= confidence_believed - Srm 

* Strong overconfidence
gen soc=(confidence> 1)

* Strong under-confidence 
gen suc=(confidence< -1)

* weak overconfidence
gen oc=(confidence>= 1)

* Weak under-confidence 
gen uc=(confidence<= -1) 

*** Cognitive Reasoning	
gen rcr1=1 if cr1=="AO03" 
replace rcr1=0 if cr1!="AO03" & cr1!=""
gen rcr2=1 if cr2=="AO02"
replace rcr2=0 if cr2!="AO02" & cr2!=""
gen rcr3=1 if cr3=="AO05"
replace rcr3=0 if cr3!="AO05" & cr3!=""

gen Cr= rcr1+rcr2+rcr3
replace Cr=0 if (crawar!=. | RALaloterieàlaquellevousa!="") & Cr==. // Replace 0 if they advance to next task but did't complete the cornitive reasoning task

*** Risk-taking	
gen risk= real(substr(RALaloterieàlaquellevousa,3,4))
recode risk (1=0) (2=1) (3=2) (4=3)

*** Willingness to pay 
gen wtp= (wtp0=="Y"| wtp1=="Y"| wtp2=="Y"| wtp3=="Y")
replace wtp=. if wtp3==""
label define wtpl 0 "No wtp" 1 "Positive wtp" 
label values wtp wtpl

*** Maximum WTP
gen mwtp0= 0.5 if wtp0== "Y"
gen mwtp1=1 if wtp1== "Y"
gen mwtp2=2 if wtp2== "Y"
gen mwtp3=3 if wtp3=="Y"

gen maxwtp= max(mwtp0,mwtp1,mwtp2,mwtp3)
replace maxwtp=0 if (wtp0=="N"& wtp1=="N"& wtp2=="N"& wtp3=="N")



*-------------------------------------------------------------------------------
******** Generate secondary outcome variables
			
*** Emotions	
foreach num in  01 02 03 04 05 06 07 08 09 10 11 12 {
qui: gen emot`num'= real(substr(MSSQ`num'Voustrouverezcidess,3,4)) //Creating a variable that contains emotions before and after treatment
qui: replace emot`num'= real(substr(MSavantSQ`num'Voustrouverezci,3,4)) if random_emotions==0 
}

label define emt 1 "Certainement pas" 2 "Pas" 3 "Pas vraiment" 4 "Un peu" 5 "Très" ///
6 "Extrêmement" 7 "Ne souhaite pas répondre"

foreach var of varlist emot* {
qui: label values `var' emt
}

*** Creating the emotions score: Positive emotion score. The higher the better 
foreach num in  01 02 03 04 05 06 07 08 09 10 11 12{ 
qui: gen ms_ind`num' = emot`num'
qui: recode ms_ind`num' (7=.) // Replace as missing for those who didn't want to answer
}

foreach num in  03 04 05 07 09 11{  //Recoding negative emotions questions into positive 
qui: recode ms_ind`num'(1=6) (2=5) (3=4) (4=3) (5=2) (6=1) 
}

egen count_gb = rcount(ms_ind01 ms_ind04 ms_ind08 ms_ind11), cond(@ == .) 
egen count_at = rcount(ms_ind02 ms_ind05 ms_ind07 ms_ind10), cond(@ == .) 
egen count_cn = rcount(ms_ind03 ms_ind06 ms_ind09 ms_ind12), cond(@ == .) 

	* These scores don't include people that have stated "Ne souhaite pas répondre"
** Level of feeling good 
gen ms_gb= ms_ind01 + ms_ind04 + ms_ind08 + ms_ind11
** Level of feeling awake
gen ms_at= ms_ind02 + ms_ind05 + ms_ind07 + ms_ind10
** Level of feeling calm
gen ms_cn= ms_ind03 + ms_ind06 + ms_ind09 + ms_ind12

	* Standarised
egen ms_gb_std = std(ms_gb)
egen ms_at_std = std(ms_at)	
egen ms_cn_std = std(ms_cn)	

*** Attrition 
gen attrition=1 if (treatment!=. & date==.) // 1 if they were assigned to one of the treatments of the article and quit at any point
replace attrition=0 if finish==1
			
*** Attention 
* IMC: Instructional Manipulation Checks
gen imcq= real(substr(SJSQ03Suruneéchellede1à, 3,4))
label define im 1 "Je suis en désaccord complet" 2 "Je suis plutôt en désaccord" 3 "Je suis plutôt d'accord" ///
4 "Je suis entièrement d'accord" 5 "Refuse de répondre"
label values imcq im 

gen imc=imcq==2 //We ask them to select option 2
label define wr 1 "Correct" 0 "Inconrrect"
label values imc wr 

* Bogus
gen bogusq= real(substr(COV15SQ03Selonvousqueles, 3,4))
label define cov 1 "Nul ou quasiment nul" 2 "Faible" 3 "Moyen" 4 "Elevé" ///
5 "Ne sait pas" 6 "Refuse de répondre"
label values bogusq cov

gen bogus=1 if 	(bogusq==1 | bogusq==2)  
replace bogus=0 if (bogusq==3 | bogusq==4 | bogusq==5)		
label values bogus wr			
			
*** Attitude towards vaccination	
gen vaccine= real(substr(COV17Pensezvousvousfaireva, 3,4))
replace vaccine=6 if vaccine==. & finish==1
label define vcc 1 "certainement" 2 "probablement" 3 "je ne sais pas encore" 4 "probablement pas" ///
5 "certainement pas" 6 "je refuse de répondre"
label values vaccine vcc	

	* Positive attitude towards vaccination
gen positive_atv= 1 if inlist(vaccine, 1,2)	
replace positive_atv=0 if inlist(vaccine, 3,4,5)
label define atvposl 1 "Positive" 0 "Negative"
label values positive_atv atvposl 
			
	* Negative attitude towards vaccination
gen negative_atv= 1 if inlist(vaccine, 4,5)	
replace negative_atv=0 if inlist(vaccine, 1,2,3)
label define atvnegl 0 "Positive" 1 "Negative"
label values negative_atv atvnegl 			

		
*** Coaching choice
gen opt1= real(substr(choix1Mercidindiquercidess ,3,4))
gen opt2= real(substr(choix2Mercidindiquercidess,3,4))
label define opt 1 "Confiance en soi & Gestion du stress" 2 "Méthodologie de travail" ///
3 "Soutien psychologique" 4 "Simulation d’entretien d’embauche" 5 "Je ne sais pas" 6 "Rien ne m’intéresse"
label values opt1 opt 
label values opt2 opt 	

gen selfconf_stress= (opt1==1| opt2==1)
replace selfconf_stress=. if opt1==.
replace selfconf_stress=. if opt2==.

gen work_method= (opt1==2| opt2==2)
replace work_method=. if opt1==.
replace	work_method=. if opt2==.

gen psy_support= (opt1==3| opt2==3)	
replace psy_support=. if opt1==.
replace psy_support=. if opt2==.

gen intership= (opt1==4| opt2==4)	
replace intership=. if opt1==.
replace intership=. if opt2==.

			
*** Wanting to receive information about: 	
label define infol 1 "Yes" 0 "No"
* Informations de qualité sur la Covid-19
gen info_cov= (LiensSQ01Pourvousremercier =="Y")
label values info_cov infol
* Sport, activités, culture
gen info_sac=(LiensSQ02Pourvousremercier=="Y")
label values info_sac infol
* Services d'aide AMU
gen info_aid=(LiensSQ03Pourvousremercier=="Y")
label values info_aid infol
* Ressources d'orientation professionnelle
gen info_op= (LiensSQ04Pourvousremercier=="Y")
label values info_op infol
* Non merci
gen info_no= (LiensSQ05Pourvousremercier=="Y")
label define nf 1 "Do not want info" 0 "Want info"
label values info_no nf							



*-------------------------------------------------------------------------------
******** Generate control variables	
		
* Age
split birth, p("-") destring  // to subtract the year from the format "1999-01-01 00:00:00"
split birth1, p(" ") destring // bc some obs have different format "01jan1999 00:00:00"
gen dbirth=real(substr(birth11,6,.))

replace birth1= birth3 if birth2==.
destring birth1, replace
replace dbirth= birth1 if dbirth==.

g year= 2021
g age= year-dbirth
drop birth1 birth2 birth3 birth11 birth12 year

* Gender
gen gender= real(substr(B3Quelestvotresexe,3,4))
recode gender (1=0) (2=1) (3=2) (4=3) 
label define gender 0 "Man" 1 "Woman" 2 "Non-binary" 3 "NA"
label values gender gender

gen woman = (gender == 1)

* Bourse 
gen bourse= real(substr(B4Bénéficiezvousdunebourse,3,4))
recode bourse (1=0) (2=1) (3=2)
label define noyes 0 "No" 1 "Yes" 2 "NA"
label values bourse noyes

* Schooling 	
gen schooling= real(substr(B6Enquelleannéedétudeêtes,3,4))
label define b6 0 "L1" 1 "L2" 2 "L3" 3 "Licence Pro" 4 "M1" 5 "M2" ///
6 "Doctorat" 7 "1ère année de DUT ou de DEUST" 8 "2ème année de DUT ou de DEUST" ///
9 "1ère année de prépa" 10 "2ème année de prépa" 11 "1ère année d'école d'ingénieurs" ///
12 "2ème année d'école d'ingénieurs" 13 "3ème année d'école d'ingénieurs" 14 "Other"
label value schooling b6

	* Manually classify schooling from "other".		
replace schooling=0 if inlist(schooling_oth, "1ere année de médecine", "Doublante PACES", "PACES", "PASS", "Pass")
replace schooling=1 if inlist(schooling_oth, "2ème année à l'IEP", "DU", "L1 LAS","capacité en droit")
replace schooling=4 if inlist(schooling_oth, "DES Santé Publique et M1", "Niveau CRFPA" )
replace schooling=5 if inlist(schooling_oth, "5ème année de médecine", "6e année médecine", "DES Gériatrie 3ème semestre", "DESU", "DESUEJ CRFPA", "Interne en biologie médicale réalisant un M2")
replace schooling=7 if inlist(schooling_oth, "Certificat Universitaire" )
replace schooling=9 if inlist(schooling_oth, "AMNS", "Année de remise à niveau", "Mise à niveau scientifique")
replace schooling=10 if inlist(schooling_oth, "2e année de prépa intégrée")
replace schooling=14 if schooling_oth== "SUFLE B1"
replace schooling=14 if schooling==. & finish==1 // Blank in Schooling_oth

* Year of study
gen ystudy= 1 if inlist(schooling, 0,1,2,3,7,8,9,10) // "Undergard": Licences, Prepa and DUT/ DEUST 
replace ystudy= 2 if inlist(schooling, 4,5,11,12,13) // "Grad": Masters and Engineers
replace ystudy= 3 if schooling==6	
replace ystudy= 4 if schooling==14
label define ysl 1 "Undergrad" 2 "Master & Engineers" 3 " PhD" 4 "Other"
label values ystudy ysl 

* Recovering level of study with faculty and age
replace ystudy=1 if ystudy==4
	// The ones with missing info were classified as Undergrad students: 
	// - One was doing sort of "French course". 
	// - The other two belong to the field of science and their average age corresponded to Undergrad

gen undergrad=ystudy==1 	
tab ystudy, gen(ystudy_)	

						
* Field
gen field= real(substr(B9Quelestvotredomainedétu ,3,4))
label define b9 0 "Arts, Lettres, Langues" 1 "Sciences de la Santé" 2 "Droit, économie, Gestion" ///
3 "Sciences  humaines et sociales" 4 "Sciences et Technologies" 5 "Other", replace
label value field b9

	* Manually classify Field from "other".		
replace field=0 if inlist(field_oth, "Géostratégie", "L.AS (Licence Accès Santé) en Lettres modernes", "Sciences, lettres")	
replace field=1 if inlist(field_oth, "Orthophonie", "PACES", "maieutique", "médecine")
replace field=2 if inlist(field_oth, "Commerce", "GEA", "GRH, management des équipes de soins", "Logistique et Transport", "Tourisme") 
replace field=3 if inlist(field_oth, "Communication","Education","Enseignement","Gestion Urbaine","Information Communication option métiers du livre")
replace field=3 if inlist(field_oth, "Information-communication", "MEEF","MEEF SES","Métier de l'éducation de l'enseignement et de la formation","Philosophie","Professorat", "Professorat des écoles")
replace field=3 if inlist(field_oth, "Psychologie","SCIENCES POLITIQUES","Science et humanités","Science politique","Sciences Politiques","Sciences et Humanité", "Sciences et Humanités")
replace field=3 if inlist(field_oth, "Sciences politiques", "Techniques de commercialisation", "professorat des écoles", "psychologie", "Humanités/sciences sociales aux Etats Unis et Physique Chimie à distance en parallèles")
replace field=4 if inlist(field_oth, "Agronomie", "ECO-RSE", "Education et motricité", "Gestion de l'environnement et métiers de l'eau" )
replace field=4 if inlist(field_oth, "Génie mécanique et productique", "Génie-Civil", "Humanités/sciences sociales aux Etats Unis et Physique Chimie à distance en parallèles")
replace field=4 if inlist(field_oth, "Hygiène, Sécurité, Environnement", "INFORMATIQUE", "Informatique", "Licence trans et pluri disciplinaire", "Hygiène sécurité et environnement" )
replace field=4 if inlist(field_oth, "MMI", "MP", "Métiers du Livre et du Patrimoine", "STAPS", "Science de la Vie", "Sciences") 
replace field=4 if inlist(field_oth, "informatique", "mathématiques", "Sciences du sport", "Sport")	
replace field=5 if inlist(field_oth, "Prépa")	
	
	* "other" if participants finished the survey but didn't answer the field question	(8 participants)	
gen field_blank= 1  if finish==1 & field==.	
replace field=5 if field_blank==1	
drop field_blank	
	
	* We impute the observations without birth date with the average age by field
bysort field: egen age_field= mean(age)
replace age= age_field if age==. & finish==1
replace age= int(age)

tab field , gen(field_)
	
	
* Faculty
gen faculty=real(substr(B10Quelleestvotrefacultéc,3,4))
label define b10 1 "Faculté des Arts, Lettres, Langues et Sciences Humaines / Centre de formation des musiciens intervenants / MMSH" ///
2 "Faculté de Droit et de Science Politique / Institut de Management Public et Gouvernance Territoriale" ///
3 "Faculté d'économie et de Gestion / IAE Aix-Marseille / école de Journalisme et de Communication d'Aix-Marseille" ///
4 "Faculté d'Odontologie / Faculté de Pharmacie" ///
5 "Faculté des Sciences Médicales et Paramédicales" ///
6 "Faculté des Sciences / Faculté des Sciences du Sport" ///
7 "Polytech Marseille / Institut Pythéas - Observatoire des sciences de l'univers" ///
8 "IUT d'Aix-Marseille Université" ///
9 "Institut national supérieur du professorat et de l'éducation d'Aix-Marseille" 
label value faculty b10

replace faculty=1 if inlist(faculty_oth, "SUFLE")
replace faculty=2 if inlist(faculty_oth, "IEP Aix", "IEP Aix-en-Provence", "IEP d'Aix", "IEP d'Aix en Provence", "IMPGT", "Institut de Droit des Affaires", "Sciences Po", "Sciences Po Aix")
replace faculty=3 if inlist(faculty_oth, "AMSE", "Aix Marseille School of Economics", "Centrale Marseille / AMSE", "Double licence Droit/ Economie", "IAE Aix en Provence")
replace faculty=5 if inlist(faculty_oth, "Ecole de maïeutique de Marseille", "Sciences de la Vie et de la Santé Ecole doctorale 062")
replace faculty=6 if inlist(faculty_oth, "CTES", "Environnement", "Fac des sciences et du sport", "Faculté de Science - Site de Saint Charles", "Faculté des Sciences Saint-Charles")
replace faculty=6 if inlist(faculty_oth, "Faculté des Sciences Saint-Jérôme", "Faculté des Sciences de Luminy", "Faculté des sciences de Montperrin","Faculté des sciences du sport", "Faculté saint jérome", "Informatique", "SATIS", "Saint charles", "st jerome")
replace faculty=7 if inlist(faculty_oth, "OSU Pytheas")
replace faculty=8 if inlist(faculty_oth, "FUP-AIC")

* Recovering field with faculty information
replace field=0 if faculty==1 & field==5
replace field=2 if faculty==3 & field==5
replace field=4 if faculty==6 & field==5
replace field=4 if faculty==7 & field==5
replace field=4 if faculty==8 & field==5

* Fields of study 
gen art_language = field==0
label define art_language 0 "Other" 1 "Art, Literature \& Language", replace
label values art_language art_language

gen law_econ= field==2
label define law_econ 0 "Other" 1 "Law \& Econ.", replace
label values law_econ law_econ

gen social_science = field==3
label define social_science 0 "Other" 1 "Scocial science", replace
label values social_science social_science

gen sci_tech=field==4
label define sci_tech 0 "Other" 1 "Scien. \& Tech."
label values sci_tech sci_tech

gen sante_student = (B9Quelestvotredomainedétu == "SQ01")

*-------------------------------------------------------------------------------
******** Generate extended controls variables	

* Participants' origin  
gen origin= 1 if HH1ÊtesvousnéeenFrance== "AO01"  // 1 if they were born abroad 
replace origin= 0 if HH1ÊtesvousnéeenFrance== "AO02"
replace origin= 2 if HH1ÊtesvousnéeenFrance== "AO03"
label define origin 1 "Born abroad" 0 "Born in France" 2 "NA"
label values origin origin

gen frborn=origin==1
gen migrant = (HH4VotrepèreestilnéenFra == "AO02" & HH6Votremèreestellenéeen == "AO02")

* Parents' origin 
gen parents_origin=1 if (HH4VotrepèreestilnéenFra=="AO02" &	HH6Votremèreestellenéeen=="AO02") // 1 if both their parents were born abroad
replace parents_origin=0 if (HH4VotrepèreestilnéenFra=="AO01" |	HH6Votremèreestellenéeen=="AO01") // if at least one of the parents is french
replace parents_origin=2 if (HH4VotrepèreestilnéenFra=="AO03" | HH4VotrepèreestilnéenFra=="AO04")
replace parents_origin=2 if (HH6Votremèreestellenéeen=="AO03" | HH6Votremèreestellenéeen=="AO04")
label define originpl 1 "Both were born abroad" 0 "At least 1 was born in France" 2 "NA", replace
label values parents_origin originpl

gen parents_frborn=parents_origin==1


* Father's origin 					
gen father_fr=1 if HH4VotrepèreestilnéenFra=="AO01" // 1 if the father is french
replace father_fr=0 if HH4VotrepèreestilnéenFra=="AO02"	
replace father_fr=2 if (HH4VotrepèreestilnéenFra=="AO03" | HH4VotrepèreestilnéenFra=="AO04")	
label define fr 1 "French" 0 "No french" 2 "NA", replace
label values father_fr fr

* Mother's origin 			
gen mother_fr=1 if HH6Votremèreestellenéeen=="AO01" // 1 if the mother is french
replace mother_fr=0 if HH6Votremèreestellenéeen=="AO02"	
replace mother_fr=2 if (HH6Votremèreestellenéeen=="AO03" | HH6Votremèreestellenéeen=="AO04")
label values mother_fr fr	
		

* French native speaker 
gen frspeaker= 1 if HH0Votrelanguematernelleest== "Y"
replace frspeaker= 0 if HH0Votrelanguematernelleest== "N"
label define fr1 1 "French native speaker" 0 "No french native speaker"
label values frspeaker fr1
	
* Level of Fatigue
gen fatigue=real(substr(B11Quelestvotreniveaudefa ,3,4))
label define ft 1 "Extrêmement fatigué.e" 2"Très fatigué.e" 3 "Un peu fatigué.e" ///
4 "Normal" 5 "En forme / reposé.e" 6"Très en forme / très reposé.e"
label value fatigue ft

gen tired=fatigue<3

* Colorblindness
gen  daltonism= real(substr(HH38Souffrezvousdedaltonism,3,4))
recode daltonism (1=0) (2=1) (3=2)
label define cb 0 "Yes"  1 "No" 2 "NA", replace
label value daltonism cb		
	
* Time of the survey
gen submit= clock(startdateDatedelancement, "YMDhms")

gen exceltime= startdateDatedelancement if submit==.
destring exceltime, replace

gen double statatime = round((exceltime+td(30dec1899))*86400)*1000 // converting date from Excel, 1900 date system
format statatime %tc

replace submit= statatime if submit==. 

gen hour= hh(submit) 

gen time= 1 if hour>=5 & hour<12
replace time=2 if hour>=12 & hour<17
replace time=3 if hour>=17 & hour<21
replace time=4 if hour>=21
replace time=4 if hour<=4 
	
label define time 1 "Morning" 2 "Afternoon" 3 "Evening" 4 "Night", replace	
label value time time	

* Day of survey		
gen day= date(startdateDatedelancement, "YMDhms")
replace day=dofc(statatime) if day==.
format day %td				
	
* Time articles
gen timemin= timetotal/60
gen timeeconmin= timeecon/60
gen timesocialmin= timesocial/60
gen timecontrol1min= timecontrol1/60
gen timecontrol2min= timecontrol2/60

gen time_treatment= timeeconmin if treatment==1
replace time_treatment= timesocialmin if treatment==2
replace time_treatment= timecontrol1min if treatment==3
replace time_treatment= timecontrol2min if treatment==4

* week of survey 	
* gen week= week(date)
gen week=.
replace week=1 if day>= date("23022021","DMY") & day<= date("26022021","DMY")
replace week=2 if day>= date("02032021","DMY") & day<= date("05032021","DMY")
replace week=3 if day>= date("09032021","DMY") & day<= date("12032021","DMY")
replace week=4 if day>= date("16032021","DMY") & day<= date("19032021","DMY")
replace week=5 if day>= date("23032021","DMY") & day<= date("26032021","DMY")
replace week=6 if day>= date("30032021","DMY") & day<= date("02042021","DMY")

* weekday of suvey 
gen weekday=dow(day)
label define weekday 2 "Tuesday" 3 "Wednesday" 4 "Thursday" 5 "Friday", replace
label value weekday weekday	


*-------------------------------------------------------------------------------
******** Generate outliers & exclusions: See preregistration.
** Exlusions	
* Time
egen medtime= median(timetotal)
gen excltime= (timetotal< 0.2* medtime)
gen excltime2= timemin>100
* Age 
gen excltage=1 if age<18 | age>30

gen exclusions= (excltime== 1 | excltime2==1 | excltage==1)

** Outliers
* PhD students
gen phd=1 if schooling==6
* Age >27
gen outage=1 if age<18 | age >= 27



*-------------------------------------------------------------------------------
******** Generate variables for heterogeneity		

	
*** First year of undergrad
gen undergrad1=1 if inlist(schooling, 0, 7, 9) // L1, 1st DUT/DEUST, 1st prepa
replace undergrad1=0 if undergrad1==.
label define ug 1 "1st year of undergrad" 0 "No 1st year of undergrad"
label value undergrad1 ug
								
*** "Close" to go to the labor market
gen labormarket=1 if inlist(schooling, 5, 13, 6)	// M2, 3rd école d'ingénieurs, PhD
replace labormarket=0 if labormarket==.
label define lb 1 "M2/ 3rd Engineers/PhD" 0 "Others"
label value labormarket lb

gen labormarket1=1 if inlist(schooling, 5, 13)	// M2, 3rd école d'ingénieurs
replace labormarket1=0 if labormarket1==.
label define labormarket1 1 "M2/ 3rd Engineers" 0 "Others"
label value labormarket1 lb1

*** Mental health
foreach num in  01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 {
qui: gen mentalh`num'= real(substr(MH1SQ`num'Aucoursdesdeuxder,3,4))
qui: recode mentalh`num' (6=2) (2=3) (3=4) (4=5) (5=6)
}

label define mhl 1 "Jamais" 2 "Un jour" 3 "Plusieurs Jours" 4 "Plus de la moitié du temps" ///
 5 "Presque tous les jours" 6 "Refuse de répondre"
 
foreach var of varlist mentalh* {
label values `var' mhl
}
 
* Creating the Higly stressed indicator. 3 point scale. 
foreach num in  01 02 03 04 05 06 07 08 09 10 11 12 13 15 { // Don't include 14 bc bc is phrased in a possitive way
qui: gen mental_health`num'= real(substr(MH1SQ`num'Aucoursdesdeuxder,3,4))
qui: recode mental_health`num' (1=0) (6=1) (5=.)
}

foreach num in  01 02 03 04 05 06 07 08 09 10 11 12 13 15 { 
qui: recode mental_health`num'  (2=1) (3=2) (4=3) 
}

egen count_mentalh = rcount(mental_health01-mental_health15), cond(@ == .) 
tab  count_mentalh

* Mental health score 
egen mental_health_sum= rsum(mental_health01-mental_health08 mental_health13 mental_health15) 

	* We normalise it to make it comparable with the MQSP-9 (which has 9 questions)
gen mental_health_score= mental_health_sum * 9/10 if count_mentalh==0 
replace mental_health_score= mental_health_sum  if count_mentalh==1 // If they missed 1 question
replace mental_health_score= mental_health_sum * 9/8 if count_mentalh==2 // If they missed 2 questions

egen mental_health_score_std = std(mental_health_score)

	* Depression diagnostic 
gen diagnostic_depression=.
replace  diagnostic_depression=1 if (mental_health_score>=0 & mental_health_score< 5)
replace  diagnostic_depression=2 if (mental_health_score>=5 & mental_health_score< 10)
replace  diagnostic_depression=3 if (mental_health_score>=10 & mental_health_score<15)
replace  diagnostic_depression=4 if (mental_health_score>=15 & mental_health_score<20)
replace  diagnostic_depression=5 if (mental_health_score>=20 & mental_health_score<=27)
label define diagnostic 1 "Absence of depression" 2 "Light depression" 3 "Moderate depression" 4 "Moderately severe depression" 5 "Severe depression", replace
label values diagnostic_depression diagnostic

gen depression= diagnostic_depression>2

	* Median depression
egen med_depression= median(mental_health_score) if finish==1 & exclusions==0	/*The higher the worse mental health */
gen depression_score=1 if mental_health_score> med_depression & med_depression!=.
replace depression_score=0 if  mental_health_score<= med_depression  & med_depression!=.
	
*** Anxiety score (For people that awnsered all the questions)
gen anxiety_sum= mental_health09+mental_health10+mental_health11+mental_health12 
gen anxiety_score= anxiety_sum *7/4  

gen diagnostic_anxiety=.
replace diagnostic_anxiety=1 if anxiety_score<8
replace diagnostic_anxiety=2 if anxiety_score>=8 & anxiety_score <=10
replace diagnostic_anxiety=3 if anxiety_score>10 & anxiety_score <=21

label define diagnostic_anxiety 1 "Absence of anxiety" 2 "Possible anxiety" 3 "Certain anxaiety" , replace
label values diagnostic_anxiety diagnostic_anxiety	

gen anxiety= diagnostic_anxiety>1

	* Median anxiety 
egen med_anxiety= median(anxiety_sum) if finish==1 & exclusions==0	/*The higher the worse mental health */
gen anxiety_score2=1 if anxiety_sum> med_anxiety & med_anxiety!=.
replace anxiety_score2=0 if  anxiety_sum<= med_anxiety  & med_anxiety!=.

**** Locus of control 
foreach num in  01 02 03 04 07 08 {
qui: gen locus`num'= real(substr(LCSQ`num'Suruneéchellede1à,3,4))
}
label define lcl 1 "Je ne suis pas d'accord du tout" 2 "je suis plutôt pas d'accord" 3 "ni d'accord ni pas d'accord" ///
4 "je suis plutôt d'accord" 5 "je suis entièrement d'accord" 6 "ne souhaite pas répondre"	

foreach var of varlist locus* {
qui: label values `var' lcl
}		
* Creating the "Highly internally oriented" indicator. 5 point scale. Max 30	
foreach num in  01 02 03 04 07 08 {
qui: gen lc`num'= real(substr(LCSQ`num'Suruneéchellede1à,3,4))
qui: recode lc`num' (6=.)
}

foreach num in  01 04 07 {  // Recoding items that highly internally oriented subjects are expected to answer “Disagree” 
qui: recode lc`num' (1=5) (2=4) (4=2) (5=1)
}
egen count_lc = rcount(lc01-lc08), cond(@ == .) 

* Locus of control score (For people that awnsered all the questions)
egen lc_ind= rsum(lc01-lc08) if count_lc==0
egen mean_lc= mean(lc_ind)	
gen low_lc= (lc_ind< mean_lc) if lc_ind!=.
label define blc 1 "Low Locus of Control" 0 "High Locus of Control"
label value low_lc blc

egen lc_ind_std = std(lc_ind)

**** Self Judgment
** Concentration ability score. 4 point scale. Max 8 	
gen concen1= real(substr(SJSQ05Suruneéchellede1à,3,4))	
recode concen1 (5=.)
gen concen2= real(substr(SJSQ6Suruneéchellede1à,3,4))
recode concen2 (5=.)
gen ca_ind= concen1 + concen2 // The higher the score the more "vulnerable" 
	
egen mean_ca= mean(ca_ind)	
gen low_ca= (ca_ind>mean_ca) if ca_ind!=.	
label define low_ca 1 "Low concentration ability" 0 "High concentration ability"
label value low_lc blc	
			
gen low_cog_flexibility= (concen1==3 | concen1==4)
gen low_cog_control= (concen2==3 | concen2==4)
						
** Importance of academic succcess (The higher  the more important)
gen imp_dip=real(substr(EX1SQ01Quandvouspensezàv,3,4)) 
recode 	imp_dip (6=.) 
egen imp_dip_sd= std(imp_dip)

gen imp_grade=real(substr(EX1SQ02Quandvouspensezàv,3,4)) 
recode 	imp_grade (6=.) 	
egen imp_grade_sd= std(imp_grade)

** Importance of academic succcess score. 5 point scale. Max 10  
gen acad_succ= imp_dip + imp_grade 
		
** Parents(The higher  the more important)
gen imp_grade_par=real(substr(EX1SQ03Quandvouspensezàv,3,4)) 
recode 	imp_grade_par (6=.) 			

** Importance of a good career
gen belle_career= real(substr(EX1SQ04Quandvouspensezàv,3,4)) 
recode 	belle_career (6=.) 	
egen belle_career_sd= std(belle_career)
	
gen imp_job= real(substr(EX1SQ06Quandvouspensezàv,3,4))			
recode 	imp_job	(6=.) 		
egen imp_job_sd= std(imp_job)
 

** Parents (The higher  the more important)	
gen bellecar_par=real(substr(EX1SQ05Quandvouspensezàv,3,4)) 
recode 	bellecar_par  (6=.) 			
gen impjob_par=real(substr(EX1SQ07Quandvouspensezàv,3,4)) 
recode 	impjob_par (6=.) 

** Grades received in the previous semester	
gen grades= real(substr(HH36bisQuelleaétévotremoye,3,4)) 
recode grades (8=.)

** fulfilled their expectations 
gen exp_grades= real(substr(HH37Commentévaluezvousvosr,3,4))
gen expect_down= inlist(exp_grades,1,2) if grades!=. // if they performed worse than expected
label define expl 1 "Performed worse than expected" 0 "Other", replace
label values expect_down expl

gen expect_up= inlist(exp_grades,4,5) if grades!=.  // if they performed better than expected
label define expl2 1 "Performed better than expected" 0 "Other", replace
label values expect_up expl2

gen importance_grade_parents = (inlist(EX1SQ03Quandvouspensezàv, "AO04", "AO05"))
gen importance_finish_parents = (inlist(EX1SQ08Quandvouspensezàv, "AO05"))
gen low_proba_career = (inlist(EX2SQ02Quandvouspensezàv, "AO01", "AO02"))
gen low_proba_success = (inlist(EX2SQ01Quandvouspensezàv, "AO01", "AO02",  "AO03"))
gen pessimistic = (inlist(EX4SQ01DanslensembleJe, "AO01", "AO02"))

	
**** Covid experience	
gen stay_confinement=real(substr(COV1Oùavezvouspasséleprem,3,4))
replace stay_confinement=0 if COV1Oùavezvouspasséleprem=="-oth-"
label define stay_confinement 0 "Other" 1 "Dans le logement parental" 2 "Dans le logement universitaire (CROUS)" ///
3 "Logement individuel ou en colocation" 4 "Chez des amis" 5 "A l'étranger" ,replace
label values stay_confinement stay_confinement

gen company_confinement=real(substr(COV2Avecquiavezvousvécule,3,4)) 
replace company_confinement=0 if COV2Avecquiavezvousvécule=="-oth-"
label define company_confinement 0 "Other" 1 "Seul.e" 2 "Avec 1 colocataire" 3 "Avec 2 ou 3 colocataires" 4 "Avec plus de 3 autres colocataires" ///
5 "En couple" 6 "Avec votre famille" 7 "Avec partenaire et autre(s) colocataire(s)"
label values company_confinement company_confinement
	
gen employed_confinement=0 if COV3Avezvousoccupéunemploi=="N"
replace employed_confinement=1 if COV3Avezvousoccupéunemploi=="Y"	

gen howmanytest=.
replace howmanytest=0 if COV4Combiendefoisvousêtes=="AO01"
replace howmanytest=1 if COV4Combiendefoisvousêtes=="AO02"
replace howmanytest=2 if COV4Combiendefoisvousêtes=="AO03"
replace howmanytest=3 if COV4Combiendefoisvousêtes=="AO04"
replace howmanytest=4 if COV4Combiendefoisvousêtes=="AO05"
replace howmanytest=5 if COV4Combiendefoisvousêtes=="AO06"
replace howmanytest=6 if COV4Combiendefoisvousêtes=="AO08"
replace howmanytest=7 if COV4Combiendefoisvousêtes=="AO10"
replace howmanytest=8 if COV4Combiendefoisvousêtes=="AO11"
replace howmanytest=9 if COV4Combiendefoisvousêtes=="AO12"
replace howmanytest=10 if COV4Combiendefoisvousêtes=="AO13"
replace howmanytest=11 if COV4Combiendefoisvousêtes=="AO14"
replace howmanytest=12 if missing(COV4Combiendefoisvousêtes) & finish==1
	
gen selfcov= 1 if COV5Avezvousététestépositi=="Y" // If they got covid
replace selfcov= 0 if COV5Avezvousététestépositi=="N"
replace selfcov=2 if missing(selfcov) & finish==1
label define c1 1 "Had Covid" 0 "Has not had Covid" 2 "NA", replace
label values selfcov c1

gen famcov= 1 if COV9Unepersonnedevotrefami=="Y" // If anyone in their immediate family or living got covid
replace famcov= 0 if COV9Unepersonnedevotrefami=="N"
replace famcov= 2 if missing(famcov) & finish==1
label define c2 1 "Family member had Covid" 0 "Family member has not had Covid " 2 "NA", replace
label values famcov c2

gen hospcov= 1 if COV11Unepersonnedevotrefam=="Y"  //If anyone in their family had to be hospitalised for covid
replace hospcov=0 if COV11Unepersonnedevotrefam=="N" 
replace hospcov=0 if COV9Unepersonnedevotrefami=="N"
label define c3 1 "Family member had to be hospitalised" 0 "Family member has not had to be hospitalised "
label values hospcov c3 

gen deathcov= 1 if COV12Connaissezvouspersonnel=="Y" // If anyone in their family has died of covid
replace deathcov=0 if COV12Connaissezvouspersonnel=="N" 
label define c4 1 "Family member has died" 0 "Family member has not died"
label values deathcov c4 

gen emplcov= 1 if COV14Unepersonnedevotrefam=="Y" // If anyone in their family lost their job
replace emplcov=0 if COV14Unepersonnedevotrefam=="N"
replace emplcov=2 if missing(emplcov) & finish==1
label define c5 1 "Family member has lost their job" 0 "Family member has not lost their job" 2 "NA", replace
label values emplcov c5 


*** Personal covid experience
gen personal_covid=1 if (selfcov==1 | famcov==1)  // If they or anyone in their famility got covid
replace personal_covid=0 if selfcov==0 & famcov==0
replace personal_covid=2 if selfcov==2 & famcov==2
replace personal_covid=2 if selfcov==2 & famcov==0
replace personal_covid=2 if selfcov==0 & famcov==2
label define yn 2 "NA" 1 "Yes" 0 "No" 
label values personal_covid yn  

gen lockdown_alone = (COV2Avecquiavezvousvécule == "AO01")
gen lockdown_nofamily = (COV2Avecquiavezvousvécule != "AO06")

gen see_friends =.
replace see_friends = 0 if H5Surles5jourslundivendr== "AO01"
replace see_friends = 1 if H5Surles5jourslundivendr== "AO02"
replace see_friends = 2 if H5Surles5jourslundivendr== "AO03"
replace see_friends = 3 if H5Surles5jourslundivendr== "AO04"
replace see_friends = 4 if H5Surles5jourslundivendr== "AO05"
replace see_friends = 5 if H5Surles5jourslundivendr== "AO06"
replace see_friends = 6 if H5Surles5jourslundivendr== "AO07"

gen see_family =.
replace see_family = 0 if H3Surles5jourslundivendr== "AO01"
replace see_family = 1 if H3Surles5jourslundivendr== "AO02"
replace see_family = 2 if H3Surles5jourslundivendr== "AO03"
replace see_family = 3 if H3Surles5jourslundivendr== "AO04"
replace see_family = 4 if H3Surles5jourslundivendr== "AO05"
replace see_family = 5 if H3Surles5jourslundivendr== "AO06"
replace see_family = 6 if H3Surles5jourslundivendr== "AO07"

gen at_uni = .
replace at_uni = 0 if H1Surles5jourslundivendr == "AO01"
replace at_uni = 1 if H1Surles5jourslundivendr == "AO02"
replace at_uni = 2 if H1Surles5jourslundivendr == "AO03"
replace at_uni = 3 if H1Surles5jourslundivendr == "AO04"
replace at_uni = 4 if H1Surles5jourslundivendr == "AO05"
replace at_uni = 5 if H1Surles5jourslundivendr == "AO06"


*** Personal traumatic covid experience 
replace hospcov=2 if (missing(hospcov) & date!=.)  
replace deathcov = 2 if (missing(deathcov) & date!=.)

gen personal_trau_covid = 1 if (hospcov==1 | deathcov==1) & finish ==1 //If anyone in their family had to be hospitalised for covid or died of covid 
replace personal_trau_covid = 0 if hospcov==0 & deathcov==0 & finish ==1 
replace personal_trau_covid = 2 if hospcov==2 & deathcov==0 & finish ==1 
replace personal_trau_covid = 2 if hospcov ==2 & deathcov ==2 & finish ==1 
replace personal_trau_covid = 2 if hospcov ==0 & deathcov ==2 & finish ==1 
replace personal_trau_covid = 0 if famcov ==0 & deathcov==0 & finish ==1 
gen closecov = (COV9Unepersonnedevotrefam== "Y")
gen family_lost_job =  ( COV14Unepersonnedevotrefam == "Y")

*-------------------------------------------------------------------------------
******** Other variables		

*** Family background

* Parents
	
 * Parents' marital status
gen marital_parents= real(substr(HH19Quelleestlasituationma,3,4))
label define marital 1 "mariés" 2 "concubinage/cohabitation" 3 "séparés" 4 "veuf/veuve"
label values marital_parents marital 

 *Q: Votre père a-t-il un diplôme universitaire ?
gen father_diplome=1 if  HH12Votrepèreatilundiplô== "AO01" // 1 If the father has a university degree 
replace father_diplome=0 if HH12Votrepèreatilundiplô== "AO02"
replace father_diplome=2 if HH12Votrepèreatilundiplô== "AO03"
replace father_diplome=2 if missing(HH12Votrepèreatilundiplô) & finish==1
label define p1 1 "Has a university degree" 0 "Does not have a university degree" 2 "NA", replace
label values father_diplome p1 

 *Q: Votre mère a-t-elle un diplôme universitaire ? // 1 If the mother has a university degree 
gen mother_diplome=1 if HH13Votremèreatelleundip== "AO01"
replace mother_diplome=0 if HH13Votremèreatelleundip== "AO02"
replace mother_diplome=2 if HH13Votremèreatelleundip== "AO03"
replace mother_diplome=2 if missing(HH13Votremèreatelleundip) & finish==1
label values mother_diplome p1 

 *Q: Le logement de vos parents se situe-t-il en France ?
gen logement_parents=1 if HH14Lelogementdevosparents=="Y"
replace logement_parents=0 if HH14Lelogementdevosparents=="N"	
replace logement_parents=2 if missing(HH14Lelogementdevosparents) & finish==1
label define hhl 1 "Located in France" 0 "Not located in France" 2 "NA"
label values logement_parents hhl

 *Q: Quel est le type d'environnement de ce logement parental ?
gen type_logement_parents= real(substr(HH17Quelestletypedenviron,3,4))
replace type_logement_parents=5 if missing(HH17Quelestletypedenviron) & finish==1
label define logl 1 "village (moins de 3000 habitants)" 2 "petite ville (entre 3000 et 15 000 habitants)" 3 "ville moyenne (entre 15 000 et 100 000 habitants)" 4 "grande ville (plus de 100 000 habitants)" 5 "NA",replace
label values type_logement_parents logl

 *Q: Combien de pièces compte ce logement parental ? (n'incluez que les pièces d'habitation - hors salle de bain, toilette, garage, cave, etc.)
gen rooms_parents=  real(substr(HH18Combiendepiècescomptec,3,4))
replace rooms_parents=0 if missing(HH18Combiendepiècescomptec) & finish==1
label define room 0  "NA", replace
label values rooms_parents room
	
* Students living conditions 
 * Q: Habitez-vous chez (un de) vos parents durant la semaine ?
gen living_parents= 1 if HH24Habitezvouschezunde=="Y"
replace living_parents=0 if HH24Habitezvouschezunde=="N"
label values living_parents noyes

 * Q: Où habitez-vous durant la semaine?
gen locationh= real(substr(HH25Oùhabitezvousdurantla,3,4)) 
label define locl 1 "Marseille centre-ville (du 1er au 7ème arrondissement)" 2 "Marseille hors centre (du 8ème au 16ème arrondissement)" 3 "Aix centre-ville" 4 "Aix hors centre" 5 "Ailleurs"
label values locationh locl

 * Q: Dans quel type de logement habitez-vous durant la semaine ?
gen type_accommodation= real(substr(HH26Dansqueltypedelogement,3,4)) 
replace type_accommodation=6 if HH24Habitezvouschezunde=="Y"
replace type_accommodation=7 if HH26Dansqueltypedelogement== "-oth-"

label define type_accommodation 1 "CROUS" 2 "colocation" 3 "studio/appartement seul" 4 "studio/appartement en couple" 5 "chambre dans une famille" 6 "Parents"  7 "Other", replace
label values type_accommodation type_accommodation

 * Q: Quel est le montant de votre loyer mensuel ?
rename HH27otherQuelestlemontant rent 

 * Q: Avez-vous une pièce au calme pour étudier dans ce lieu ?
gen studyroom= 1 if HH28Avezvousunepièceaucal=="Y"
replace studyroom=1 if HH29Avezvousunepièceàvous=="Y" & living_parents==1 // If they have a calm place and they live with their parents 
replace studyroom= 0 if HH28Avezvousunepièceaucal=="N"
replace studyroom= 0 if HH29Avezvousunepièceàvous=="N"  & living_parents==1
label define studyl 1 "Have a calm place to study" 0 "Have not a calm place to study", replace
label values studyroom studyl

 * Q: Avez-vous une connexion internet de qualité raisonnable dans ce lieu ?
gen okinternet=1 if HH28bisAvezvousuneconnexion=="Y"
replace okinternet=0 if HH28bisAvezvousuneconnexion=="N"
replace okinternet=2 if missing(HH28bisAvezvousuneconnexion) & finish==1
label values okinternet noyes

 * Q: Avez-vous un ordinateur personnel vous permettant d'étudier et de suivre les cours à distance ?
gen personalpc=1 if  HH30Avezvousunordinateurpe=="Y"
replace personalpc=0 if HH30Avezvousunordinateurpe=="N"
label values personalpc noyes

* Self-judgment about their intelligence
 * Q: Je pense être plus intelligent que la moyenne des personnes de mon âge
gen sj_intelligence= real(substr(SJSQ7Suruneéchellede1à,3,4)) 
label values sj_intelligence im


* Social network
gen meeting_family=.
replace meeting_family=1 if H3Surles5jourslundivendr== "AO07"
replace meeting_family=2 if H3Surles5jourslundivendr== "AO01"
replace meeting_family=3 if H3Surles5jourslundivendr== "AO02"
replace meeting_family=4 if H3Surles5jourslundivendr== "AO03"
replace meeting_family=5 if H3Surles5jourslundivendr== "AO04"
replace meeting_family=6 if H3Surles5jourslundivendr== "AO05"
replace meeting_family=7 if H3Surles5jourslundivendr== "AO06"

gen meeting_friends= real(substr(H5Surles5jourslundivendr,3,4))	
gen living_with_parents = (HH24Habitezvouschezunde =="Y")
gen parents_far_away = (living_with_parents==0 & HH15Dansqueldépartementses != "AO13" & HH15Dansqueldépartementses != "AO04" & HH15Dansqueldépartementses != "AO05" & HH15Dansqueldépartementses != "AO05" & HH15Dansqueldépartementses != "AO06" & HH15Dansqueldépartementses != "AO83" & HH15Dansqueldépartementses != "AO84")
gen living_alone = ( HH26Dansqueltypedelogement == "AO01" | HH26Dansqueltypedelogement == "AO03")

						
* Financial situation
gen income_source= real(substr(F1Quelleestvotreprincipale,3,4))	
replace income_source=5 if F1Quelleestvotreprincipale=="-oth-"	
label define sourcel1 1 "Salaire" 2 "Aide familiale (argent de poche)" 3 "Bourse" 4 "Aide publique (CAF, APL, RSA...)" 5 "Other"
label value income_source sourcel1

	* Recovering recipients of state scholarship with personal income info
replace bourse=1 if income_source==3 & bourse==2 // Scholarship
replace bourse=0 if income_source==2 & bourse==2 // Family
replace bourse=0 if income_source==4 & bourse==2 // Public help
replace bourse=0 if income_source==5 & bourse==2 // Loan, pension, trading
gen scholarship = (bourse == 1)

gen job=1 if F2Avezvousunemploiétudiant== "AO01"
replace job=0 if F2Avezvousunemploiétudiant== "AO02"
replace job=2 if F2Avezvousunemploiétudiant== "AO03"
label values job noyes

gen finance_struggle= real(substr(F7Vousarrivetildêtreàco,3,4))
label define fs 1 "jamais" 2 "rarement" 3 "souvent" 4 "presque tous les mois" 5 "Je Ne souhaite pas répondre"
label values finance_struggle fs

gen savings=1 if F8Dansunmoisnormalsansgr== "Y"
replace savings=0 if F8Dansunmoisnormalsansgr== "N"
replace savings=2 if missing(F8Dansunmoisnormalsansgr) & finish==1
label values savings noyes

gen savings_tot= real(substr(F9Combienenmoyenne,3,4)) 
replace savings_tot=1 if savings==0
replace savings_tot=0 if missing(F8Dansunmoisnormalsansgr) & finish==1
label define sv 0 "NA" 1 "0" 2 "0-50 €" 3 "50-100 €" 4 "100-200 €" 5 "plus de 200 €", replace
label values savings_tot sv

gen finance_st= (finance_struggle==1 | finance_struggle==2)
replace finance_st=. if finance_struggle==5
label define fsl 1 "Do not have financial struggles" 0 "Have financial struggles"
label values finance_st fsl

gen solve_extra_expenses= 0 if F11Sivousaviezunedépensei== "N"
replace solve_extra_expenses= 1 if F11Sivousaviezunedépensei== "Y"
replace solve_extra_expenses= 2 if missing(F11Sivousaviezunedépensei) & finish==1
label values solve_extra_expenses noyes

gen having_financial_struggles = (finance_struggle ==3 |  finance_struggle == 4)
gen bourse_oneorhigh = (inlist(level_bourse, "AO02",  "AO03",  "AO04",  "AO05",  "AO06",  "AO07",  "AO08", "AO09"))
gen running_out_money = (inlist(F7Vousarrivetildêtreàco, "AO03",  "AO04"))
gen short100= (F11Sivousaviezunedépensei=="N")
gen own_salary = (F1Quelleestvotreprincipale=="AO01")
gen both_parents_work = (inlist(HH8Quelleestlasituationpro,"AO01", "AO02") ///
			& inlist(HH10Quelleestlasituationpr, "AO01","AO02"))

*-------------------------------------------------------------------------------
******** Comprehension questions 			
			
label define qc 1 "1er trimestre 2021" 2 "2ème trimestre 2021" 3 "3ème trimestre 2021" ///
4 "4ème trimestre 2021" 5 "1er trimestre 2022" 6 "2ème trimestre 2022" 7 "3ème trimestre 2022" ///
8 "4ème trimestre 2022" 9 "pas avant 2023" 10 "jamais" 11 "je ne sais pas"
label define q6 1 "très intéressant" 2 "intéressant" 3 "peu intéressant" 4 "très peu intéressant"
label define q7 1 "j'ai beaucoup appris (je connaissais peu/pas le sujet du texte)" 2 "j'ai appris quelques nouvelles informations (je connaissais un peu le sujet du texte)" 3 "je n'ai rien appris (je connaissais bien le sujet du texte)"
label define space 1 "En 2022" 2 "En 2023" 3 "En 2024" 4 "En 2025" 5 "Entre 2026 et 2030" ///
6 "Entre 2031 et 2035" 7 "Entre 2036 et 2040" 8 "Entre 2041 et 2049" ///
9 "Pas avant 2050" 10 "Jamais " 11 "Je ne sais pas"


*** Econ treatment	
gen econ_cq1= 1 if TE1Choisissezparmilespropos== "AO03"
replace econ_cq1= 0 if TE1Choisissezparmilespropos!= "AO03" & treatment==1
gen econ_cq2=1 if TE2Selonlarticlecommenton== "AO02" 
replace econ_cq2=0 if TE2Selonlarticlecommenton!= "AO02" & treatment==1
gen econ_cq3=1 if TE3Selonlarticleetlinfogr== "AO01"
replace econ_cq3=0 if TE3Selonlarticleetlinfogr!= "AO01" & treatment==1
gen econ_cq4=1 if TE4Selonlarticleetlegraph== "AO04"
replace econ_cq4=0 if TE4Selonlarticleetlegraph!= "AO04" & treatment==1
gen econ_q5= real(substr(TE5Selonvousquandlarécess,3,4))
label values econ_q5 qc
gen econ_q6= real(substr(TE6Avezvoustrouvélarticle ,3,4))
label values econ_q6 q6
gen econ_q7= real(substr(TE7Avezvousapprisdenouvell,3,4))
label values econ_q7 q7


*** Social treatment
gen soc_cq1 =1 if TS1Choisissezparmilespropos== "AO01"
replace soc_cq1 =0 if TS1Choisissezparmilespropos!= "AO01" & treatment==2
gen soc_cq2 =1 if TS2Danslalistecidessousq== "AO05"
replace soc_cq2 =0 if TS2Danslalistecidessousq!= "AO05" & treatment==2
gen soc_cq3 =1 if TS3SelonlOVEquelleproport== "AO02"
replace soc_cq3 =0 if TS3SelonlOVEquelleproport!= "AO02" & treatment==2
gen soc_cq4 =1 if TS4SelonleCN2Rquellepropo == "AO02"
replace soc_cq4 =0 if TS4SelonleCN2Rquellepropo!= "AO02" & treatment==2
gen soc_q5= real(substr(TS5Selonvousquandnosactiv,3,4))
label values soc_q5 qc
gen soc_q6= real(substr(TS6Avezvoustrouvélarticle ,3,4))
label values soc_q6 q6
gen soc_q7= real(substr(TS7Avezvousapprisdenouvell,3,4))
label values soc_q7 q7

*** Control 1	
gen cont_cq1= 1 if C1Choisissezparmilesproposi== "AO02"
replace cont_cq1=0 if C1Choisissezparmilesproposi!= "AO02" & treatment==3
gen cont_cq2= 1 if C2Selonlarticlecombiende== "AO04"
replace cont_cq2= 0 if C2Selonlarticlecombiende!= "AO04" & treatment==3
gen cont_cq3= 1 if C3Selonlarticleetlegraphi== "AO03"
replace cont_cq3= 0 if C3Selonlarticleetlegraphi!= "AO03" & treatment==3
gen cont_cq4= 1 if C4Selonlarticlequelleprop== "AO03"
replace cont_cq4= 0 if C4Selonlarticlequelleprop!= "AO03" & treatment==3
gen cont_cq5= 1 if C5Selonlarticleetlinfogra== "AO02"
replace cont_cq5= 0 if C5Selonlarticleetlinfogra!= "AO02" & treatment==3
gen cont_q6= real(substr(C6Avezvoustrouvélarticlei ,3,4))
label values cont_q6 q6
gen cont_q7= real(substr(C7Avezvousapprisdenouvelle,3,4))
label values cont_q7 q7

*** Control 2	
gen cont2_cq1= 1 if CS1Choisissezparmilespropos== "AO02"
replace cont2_cq1=0 if CS1Choisissezparmilespropos!= "AO02" & treatment==4
gen cont2_cq2= 1 if CS2Selonletexteenquellea== "AO01"
replace cont2_cq2= 0 if CS2Selonletexteenquellea!= "AO01" & treatment==4
gen cont2_cq3= 1 if CS3Selonletexteenquellea== "AO01"
replace cont2_cq3= 0 if CS3Selonletexteenquellea!= "AO01" & treatment==4
gen cont2_cq4= 1 if CS4Selonletexteetlegraphi == "AO02"
replace cont2_cq4= 0 if CS4Selonletexteetlegraphi != "AO02" & treatment==4
gen cont2_q5= real(substr(CS5Selonvousquandunhumain,3,4))
label values cont2_q5 space
gen cont2_q6= real(substr(CS6Avezvoustrouvélarticle ,3,4))
label values cont2_q6 q6
gen cont2_q7= real(substr(CS7Avezvousapprisdenouvell,3,4))
label values cont2_q7 q7			
			
			
*** self-reflection
foreach num in  01 02 03 04 05 {
qui: gen selfref`num'= real(substr(TERefSQ`num'Suruneéchellede,3,4)) 
qui: replace selfref`num'= real(substr(TSRefSQ`num'Suruneéchellede,3,4)) if treatment==2
qui: replace selfref`num'= real(substr(CRefSQ`num'Suruneéchellede1,3,4)) if treatment==3
qui: replace selfref`num'= real(substr(CSRefSQ`num'Suruneéchellede,3,4)) if treatment==4
qui: replace selfref`num'=. if selfref`num'==5
}			
recode selfref01 (1=4) (2=3) (3=2) (4=1) if treatment==3 // Worded in a negative way

egen count_selfr = rcount(selfref01-selfref05), cond(@ == .) 
egen selfr_ind= rsum(selfref01-selfref05) if count_selfr==0

egen mean_selfr= mean(selfr_ind)	
gen selfr_high= (selfr_ind> mean_selfr)	
label define sl 1 "High self-reflection" 0 " Low self-reflection"
label values selfr_high sl


foreach num in  01 02 03 04 05 {
gen econ_ref`num'= real(substr(TERefSQ`num'Suruneéchellede,3,4)) 
}

foreach num in  01 02 03 04 05 {
gen social_ref`num'= real(substr(TSRefSQ`num'Suruneéchellede,3,4)) 
}

*** comprehension	
gen comprehension1=(TE1Choisissezparmilespropos=="AO03"|TS1Choisissezparmilespropos=="AO01"|CS1Choisissezparmilespropos=="AO02"|C1Choisissezparmilesproposi=="AO02")
gen comprehension2=(TE2Selonlarticlecommenton=="AO02"|TS2Danslalistecidessousq=="AO05"|CS2Selonletexteenquellea=="AO01"|C2Selonlarticlecombiende=="AO04")
gen comprehension3=(TE3Selonlarticleetlinfogr=="AO01"|TS3SelonlOVEquelleproport=="AO02"|CS3Selonletexteenquellea=="AO01"|C3Selonlarticleetlegraphi=="AO03")
gen comprehension4=(TE4Selonlarticleetlegraph=="AO04"|TS4SelonleCN2Rquellepropo=="AO02"|CS4Selonletexteetlegraphi=="AO02"|C4Selonlarticlequelleprop=="AO03")
gen comprehensionall=comprehension1==1&comprehension2==1&comprehension3==1&comprehension4==1

gen comprehensionscore=comprehension1+comprehension2+comprehension3+comprehension4
			
			
*-------------------------------------------------------------------------------
* Labels
label variable treatment "Article treatment"
label variable payment "Payment treatment"
label variable treat1 "Article treatment pooled"
label variable random_emotions "Emotions questionnaire treatment"
label variable treatment_after "Emotions questionnaire treatment | article treatment"
label variable age "Age"
label variable gender "Gender"
label variable bourse "Have scholarship" 
label variable schooling "Schooling" 
label variable ystudy "Year of study" 
label variable field "Field of study" 
label variable Frm "First round of matrices" 
label variable Srm "Cognitive Ability"
label variable confidence_believed "Believed number of correct matrices"
label variable confidence "Confidence"
label variable soc "Strong overconfidence"
label variable suc "Strong underconfidence"
label variable oc "Overconfidence"
label variable uc "Underconfidence"
label variable Cr "Cognitive reasoning"
label variable risk "Risk taking"
label variable wtp "Willingness to pay"
label variable maxwtp "Max willingness to pay"	
label variable ms_gb "Feeling good"
label variable ms_at "Feeling awake"
label variable ms_cn "Feeling calm"
label variable attrition "Attrition"
label variable imc "Instructional Manipulation Checks"
label variable bogus "Bogus attention check"
label variable positive_atv "Positive attitudes towards vaccination"
label variable negative_atv "Negative attitudes towards vaccination"
label variable selfconf_stress "Coaching choice: Self confidence & stress"
label variable work_method "Coaching choice: Working methodology"
label variable psy_support "Coaching choice: Psychological support"
label variable intership "Coaching choice: Intership"
label variable info_cov "Information about covid"
label variable info_sac "Information about sports and cultural activities"
label variable info_aid "Information about help from AMU"
label variable info_aid "Information about career counseling"
label variable info_no "None"
label variable	origin "Participants' origin"	
label variable	parents_origin "Parents' origin"
label variable	father_fr "Father is french"
label variable	mother_fr "Mother is french"
label variable	frspeaker "Participant is French native speaker"
label variable	fatigue "Level of fatigue"
label variable	daltonism "Colorblindness"
label variable	time "Time in which participants responded to the survey"
label variable	day "Day in which participants responded to the survey"
label variable	week "Week in which participants responded to the survey"
label variable	weekday "Day of the week in which participants responded to the survey"
label variable undergrad1 "First year of undergrad"
label variable labormarket "Close to go the labor market"
label variable mental_health_score "Mental health score"
label variable diagnostic_depression "Diagnostic depression"
label variable anxiety_score "Anxiety score"
label variable lc_ind "Locus of control"
label variable ca_ind "Concentration ability"
label variable imp_dip "Importance of having a diploma"
label variable imp_grade "Importance of having good grades"
label variable imp_grade_par "Importance of having good grades- Parents"
label variable belle_career "Importance of having a good career"
label variable imp_job "Importance of having a good job"
label variable grades "Grades received in the previous semester"
label variable exp_grades "Expected grades"
label variable expect_down "Performed worse than expected"
label variable expect_up "Performed better than expected"
label variable company_confinement "Had company during the confinement"
label variable employed_confinement "Employed during confinement"
label variable howmanytest "Number of covid test taken"
label variable selfcov "Had covid"	
label variable famcov "Family member had covid"
label variable hospcov "Family member was hospitalized"
label variable deathcov "Family member died of covid"
label variable emplcov "Family member lost job"
label variable personal_covid	"Had a close covid experience"
label variable personal_trau_covid "Had a traumatic covid experience"
label variable comprehensionscore "Comprehension score"
label variable meeting_family "Meeting with family"
label variable meeting_friends "Meeting with friends"
label variable having_financial_struggles	"Have financial struggles"		
label variable own_salary "Have own salary"
label variable both_parents_work "Both parents work"
label variable lockdown_alone "Spent lockdown alone"
label variable lockdown_nofamily "Spent without family"
label variable lockdown_alone "Spent lockdown alone"
label variable see_friends "How many days per week met friends"
label variable see_family "How many days per week met family"
label variable at_uni "How many days per week went to uni"
label variable labor_market "Labor Market"
label variable mental_health "Mental Health"
label variable parents_frborn "Parents' born in France"
label variable frborn "Born in France"
label variable undergrad "Undegrad student"
label variable ystudy_1 "Undergrad"
label variable ystudy_2 "Master and Engineers"
label variable ystudy_3 "PhD"
label variable field_1 "Arts and Languages"
label variable field_2 "Health Sciences"
label variable field_3 "Law, Economics, Management"
label variable field_4 "Humanities and Social Sciences" 
label variable field_5 "Science and Technology"
label variable woman "Woman"
label variable scholarship "Scholarship"
label variable tired "Tired"

save "${replication}/Data/worries_cognitive_performance", replace







